<template>
  <div class="about" :class="{ 'margin-left': !$store.state.ml }">
    <div class="content-container">
      <div class="search flex1">
        <div><span class="red">*</span> 属性分类</div>
        <el-input v-model="input3" class="eeeinput input">
          <el-select
            class="dw"
            v-model="select"
            slot="prepend"
            placeholder="请选择"
            clearable
          >
            <el-option
              v-for="(item, index) in newarr1"
              :label="item.value"
              :value="item.value"
              :key="index"
            ></el-option>
          </el-select>
        </el-input>
      </div>
      <div class="search flex1">
        <div><span class="red">*</span> 属性名称</div>
        <el-input class="input" placeholder="" v-model="input" clearable>
        </el-input>
      </div>

      <!-- 按钮 -->
      <span class="btn"></span>
      <el-button @click="addbrandlist" type="primary">保存</el-button>
      <el-button @click="cancel">取消</el-button>
    </div>

    <div class="flex bottom">
      <p>
        <b>Copyright © 2016-2019 </b> <span class="qdl">叩丁狼</span>. All
        rights reserved.
      </p>
      <p><b>Version</b> 1.0.0</p>
    </div>
  </div>
</template>
<script>
import { getattributeapi, getattributestore } from "../request/httpApi";
export default {
  data() {
    return {
      input: "",
      input2: "",
      input3: null,
      dialogImageUrl: "",
      dialogVisible: false,
      value: false,
      value2: false,
      textarea: "",
      id: 0,
      handleSize: 10,
      handleCurrent: 1,
      input: "",
      count: 0,
      currentPage4: 1,
      tableData: [],
      restaurants: [],
      state: "",
      timeout: null,
      iiid: null,
      optiontitle: "",
      newarr1: [],

      input3: "",
      select: "",
    };
  },
  created() {
    getattributeapi({
      page: "1",
      name: "",
      size: "10000",
      c_id: null,
    }).then((okk) => {
      console.log(okk);
      this.id = okk.data.data[0].id + 1;
      let arr = okk.data.data;
      let newarr = arr.map((e) => {
        // console.log(e);
        // console.log(e.attribute_category_id);
        // console.log(obj[value]);
        let obj = {
          value: e.attribute_category_id + "",
          address: e.attribute_category_id + "",
        };
        // console.log(obj);
        return obj;
        // obj[value] = e.attribute_category_id;
      });
      var unique = {};
      newarr.forEach(function (gpa) {
        unique[JSON.stringify(gpa)] = gpa;
      });
      newarr = Object.keys(unique).map(function (u) {
        return JSON.parse(u);
      });
      this.newarr1 = newarr;
    });
  },
  methods: {
    addbrandlist() {
      if (this.input.trim()) {
        getattributestore({
          //   id: +this.id,
          attribute_category_id: +this.select,
          name: this.input,
          input_type: 0,
          values: "",
          sort_order: 0,
          is_show: false,
          is_new: false,
        }).then((okk) => {
          console.log(okk);
          this.$router.push("/attribute");
        });
      } else {
        alert("非空");
        // 一会加样式
      }
    },
    cancel() {
      this.$router.push("/attribute");
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
  },
};
</script>


<style lang = "less" scoped>
.eeeinput {
  margin-right: 165px;
  margin-left: 10px;

  width: 0px;
  position: relative;
  .dw {
    position: absolute;
    top: 10px;
    left: 19px;
    border: 1px solid #dcdfe6;
    background-color: #fff;
    width: 200px;
    overflow: hidden;
    border-radius: 4px;
  }
}
.btn {
  margin-left: 70px;
}
.flex1 {
  display: flex;
  margin-bottom: 10px;
  width: 280px;
  justify-content: space-between;
  align-items: center;
}
.imgpr {
  padding-right: 10px;
  box-sizing: border-box;
}
.red {
  color: red;
  font-size: 8px;
}
.img {
  font-size: 12px;
}
.switch {
  font-size: 12px;

  span {
    margin-right: 85px;
  }
}
.search {
  margin: 10px 0 15px;
  font-size: 12px;
  .input {
    width: 200px;
    margin-right: 10px;
    /* height: 32px;
    line-height: 32px; */
  }
  /* .text{
      height: 200px;
  } */
}
</style>